package com.databaseconnectionmobilapi.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.RequestFacade;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 自定义过滤器
 *
 * Order代表优先级越小越先运行
 * @author Fall
 */
@Order(1)
@WebFilter(urlPatterns = "/*", filterName = "filterController")
@Slf4j
public class FilterController implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
      log.info("过滤器初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("正在过滤 " + ((RequestFacade) servletRequest).getRequestURI() + " 请求");
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {
        log.info("过滤器销毁");
    }
}
